package com.atguigu.juc1205.fileoperation;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Joey
 * @Date 2021/11/16 17:32
 * @Description 函数组合成类
 */
public class ExcelUtil {


    public static String getDate(HSSFRow row, int i) throws ParseException {
        String date = getrowData(row, i);
        if (!date.contains("(")) {
            return date;
        }
        date = date.substring(0, date.indexOf("("));
        return date;
    }

    public static String getrowData(HSSFRow row, int i) {
        return row.getCell(i).getStringCellValue();
    }

    static List<OriginalData> getData(String filePath) throws IOException, ParseException {
        List<OriginalData> result = new ArrayList<>(256);
        FileInputStream file = new FileInputStream(new File(filePath));
        HSSFSheet sheet = new HSSFWorkbook(file).getSheetAt(0);
        for (int j = 1; j < sheet.getLastRowNum() + 1; j++) {
            OriginalData originalData = new OriginalData();
            //函数组合成变换
            originalData.build(sheet.getRow(j));
            result.add(originalData);
        }
        return result;
    }
}
